import logging
import config


class RechargeApi:

    def __init__(self, session):
        # 接收session对象的变量
        self.session = session

    # 获取充值验证码接口
    def get_recharge_verify_code(self, r):
        url = config.BASE_HOST + "/common/public/verifycode/{}".format(r)
        response = self.session.get(url=url)
        logging.info("获取充值验证码接口返回的响应状态码：{}".format(response.status_code))
        return response

    # 充值接口
    def recharge(self, amount_v, valicode_v, paymentType_v="chinapnrTrust", formStr_v="reForm"):
        # 定义一个字典变量，用来接收请求体数据
        url = config.BASE_HOST + "/trust/trust/recharge"
        from_dict = {"amount": amount_v, "valicode": valicode_v, "paymentType": paymentType_v, "formStr": formStr_v}
        response = self.session.post(url=url, data=from_dict)
        logging.info("充值接口返回的数据：{}".format(response.json()))
        return response

    # 第三方充值接口
    def third_recharge(self, url, from_dict):
        response = self.session.post(url=url, data=from_dict)
        logging.info("充值接口返回的数据：{}".format(response.text))
        return response
